from typing import Optional, Dict, Callable

"""请求参数类"""
class Request:
    def __init__(
            self, url,*,
            headers: Optional[Dict] = None,
            cookies: Optional[Dict] = None,
            callback: Optional[Callable] = None,
            proxy: Optional[str] = None,
            body : Optional[Dict] = None,
            method:str = 'GET',
            priority: int = 0,
            encoding: str = 'utf-8',
            meta: Optional[Dict] = None,
            dont_filter: bool = False,
    ):
        self.url = url
        self.headers = headers if headers else {}
        self.cookies = cookies
        self.proxy = proxy
        self.body = body
        self.method = method.lower()
        self.priority = -priority
        self.callback = callback
        self.encoding = encoding
        self._meta = meta if meta is not None else {}
        self.dont_filter = dont_filter

    def __str__(self):
        return f"{self.url} {self.method}"

    def __lt__(self, other):
        return self.priority < other.priority

    @property
    def meta(self):
        return self._meta